import urllib.request
import urllib.parse
import json

url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
heads = {
    'Accept':'*/*',
    'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Acs-Token':'1704625652347_1704682905625_QAOhtCzUT2XtYdXjlG1BcwUF/fLwgHVPpIwSYhwFCRx6A21ZPmZ8dnPR6bBZRuNnnYnhGGm1wu0QlqlCc1zuFTzdOfKp2CcseX1F5gPmD5a5hUDj8JqZayl5mikhI216bN+/WOTIO/Gd+jj7KilFiagJPdh1Szy28dC9zdNd76j8WUwiU4od2LemV14A26PNAHHr0qDl/fXOWsgvHMH3RMGhjFyqKA/aLV4lhbAjYJnWpSpddBtxytDBTtAi1e07Ql9mtrcikEhTiSW8UyP+yy3eLLN6qr/vqq7rg8dlTw+tp+jj65BaGb/0XXqrevEpkk8FKlyw7zXPBIm1nKQGKf2mn1e6KnmWXR2C66ROTa/78lKqbr2v0n9GKm5uodJ5VPNJ6VY+u7WAbYjO3yLyHQjFmYjQPX3KKTZLgn6/PNWxRj5PvE94/KyPmjpW+w1WyNuldAO6KAvAORHIk56W84EW+u3omQIFbWKih+kCdAoog9qZAfw8zv5v/ugenFr7',
    'Connection':'keep-alive',
    'Content-Length':'133',
    'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie':'BIDUPSID=5489A9E827971EF6E5736F51CCA6D2EB; PSTM=1639732408; BAIDUID=B15CCF5A5693708E9EF66AC762BA35E1:FG=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; H_WISE_SIDS=234020_110085_274776_275733_278574_278621_278791_278388_279020_279998_278414_259642_280899_280636_203517_281037_277162_279202_281392_281520_281723_281151_281808_280167_281866_281891_281829_280650_281996_279749_280106_281053_279010_282838_282996_280809_283073; H_WISE_SIDS_BFESS=234020_110085_274776_275733_278574_278621_278791_278388_279020_279998_278414_259642_280899_280636_203517_281037_277162_279202_281392_281520_281723_281151_281808_280167_281866_281891_281829_280650_281996_279749_280106_281053_279010_282838_282996_280809_283073; MCITY=-131%3A; H_PS_PSSID=39999_40011_40045; BAIDUID_BFESS=B15CCF5A5693708E9EF66AC762BA35E1:FG=1; ZFY=6AcMnIUrbYhSNCDdfnQjBTgPx6QB7u761f4sfZH0v1s:C; BDRCVFR[7UIlSC5rFcC]=mk3SLVN4HKm; BA_HECTOR=0524012h04a024a0a5a180agh5nbup1ipmjca1s; PSINO=1; delPer=0; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1704676772; ab_sr=1.0.1_YmNlNzJmNzAwNTllZjNjNzg0M2JhZjVlMWMwMWFhOTViZTc0NWMzNjA3YTBlM2YxODM0YWJiZjNhNGY4ZmNmM2E4YjJkZDBmZmViNzFmNTBkYTBkNzViNTIyYzE2YmUyYTA4ZTgwNDE2MmI1ZjI1M2Y2NjIzMGMwZGZlMzAxM2M0NGJkMDU4NDkzMTJmMTE3MGFhODc1YmU2MmEyMmI3NQ==; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1704682905',
    'Host':'fanyi.baidu.com',
    'Origin':'https://fanyi.baidu.com',
    'Referer':'https://fanyi.baidu.com/?aldtype=16047',
    'Sec-Ch-Ua':'"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',
    'Sec-Ch-Ua-Mobile':'?0',
    'Sec-Ch-Ua-Platform':'"Windows"',
    'Sec-Fetch-Dest':'empty',
    'Sec-Fetch-Mode':'cors',
    'Sec-Fetch-Site':'same-origin',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
    'X-Requested-With':'XMLHttpRequest',
}


data = {
    'from':'en',
    'to':'zh',
    'query':'lave',
    'transtype':'realtime',
    'simple_means_flag':'3',
    'sign':'396552.192057',
    'token':'215280c13862b5df5b789caebbacc182',
    'domain':'common',
}


data = urllib.parse.urlencode(data).encode('utf-8')

requests = urllib.request.Request(url = url,data = data,headers = heads)
opens = urllib.request.urlopen(requests)

com = opens.read().decode('utf-8')
# print(com)


obj = json.loads(com)
print(obj)